package net.zjitc.object.random;

import java.util.Random;

/**
 * @Author admin
 * @Date 2019/3/15 8:15
 * 产生随机数，判断猜大猜小，猜测次数
 * 属性：私有的
 * 方法：set/get方法、构造方法、特殊功能
 */
public class Guess {
    private int random;
    private int count;



    Guess() {
    }

    Guess(int random, int count) {
        this.random = random;
        this.count = count;
    }

    /**
     * 产生随机数
     *
     * @return
     */
    public int getRandom() {
        /* 创建Random对象，调用它的nextInt()得到随机数*/
        Random r = new Random();
        this.random = r.nextInt(10) + 1;
        return random;
    }

    public void setRandom(int random) {
        this.random = random;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    /**
     * 判断猜测的值g 与随机数random是否相等，
     * 猜测次数累加
     * @param g
     * @return
     */
    public String judge(int g) {
        count++;
        if(g>random){
            return "bigger";
        }else if(g<random){
            return "smaller";
        }else{
            return "binGo";
        }
    }
}
